package log4j.my;

import java.io.IOException;
import java.io.OutputStreamWriter;
import org.apache.log4j.AsyncAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

public class AsyncLog {

    public static void main(String[] args) throws IOException {
        // logger
        Logger logger = Logger.getLogger(AsyncLog.class);  
        // appender
        FileAppender appender = new FileAppender();
        logger.addAppender(appender);
        // layout
        PatternLayout layout = new PatternLayout("%-5p %r [%t] %m%n");
        appender.setLayout(layout);
        appender.setFile("d://log.txt");
        // async     
         try{
             logger.setAdditivity(false);
             AsyncAppender asyncAppender = (AsyncAppender) Logger.getRootLogger().getAppender("ASYNC");
             asyncAppender.setBufferSize(4);
         } catch (Exception e){
             System.out.println("error: " + e.toString());
         }
        
//        PatternLayout fileLayout = new PatternLayout("%-5p %r [%t] %m%n");
////        fileAppender.setLayout(fileLayout);
////         logger.getAppender("fileAppender");
//        
//        FileAppender fileAppender = new FileAppender(fileLayout, "d://log.txt");
//         logger.addAppender(fileAppender);
//         System.out.println(logger.getAllAppenders()); 
////        AsyncAppender asyncAppender;
////        asyncAppender = (AsyncAppender) logger.getAppender("fileAppender");
////        asyncAppender.setBufferSize(4);

        
        // Test
        for (int i = 0; i < 10000; i++) {
            logger.info("Это " + i);
        }
    }
}
    